using System;
using System.Collections.Generic;
using System.IO;
using System.Resources;
using System.Text;
using TmxUtil;

namespace TmxLib
{
    public class DataNodeInfo
    {
        private ResX _resX;
        private ResXDataNode _dataNode;
        private string _fileRef;


        public DataNodeInfo(ResX resX, ResXDataNode dataNode, string fileRef)
        {
            if (resX == null)
                throw new ArgumentNullException("resX");

            if (dataNode == null)
                throw new ArgumentNullException("dataNode");

            _resX = resX;
            _dataNode = dataNode;
            _fileRef = fileRef;
        }

        public string Name
        {
            get { return _dataNode.Name; }
        }

        public bool IsRef
        {
            get { return _fileRef != null; }
        }


        public ResX ResX
        {
            get { return _resX; }
        }


        public ResXDataNode DataNode
        {
            get { return _dataNode; }
        }


        public string FileRef
        {
            get
            {
                if (!IsRef)
                    throw new InvalidOperationException("ResXDataNode is not has no file reference");
                
                return _fileRef;
            }
        }

        public string FileRefFullName
        {
            get
            {
                if (!IsRef)
                    throw new InvalidOperationException("ResXDataNode is not has no file reference");

                string rxFolder = new FileInfo(this.ResX.FullName).DirectoryName;
                string ret = Path.Combine(rxFolder, this.FileRef);
                return new FileInfo(ret).FullName;
            }
        }
    }
}
